package Clases.diagram.edit.parts;

import org.eclipse.draw2d.GridData;
import org.eclipse.draw2d.GridLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;

/**
 * @generated
 */
public class PointcutEditPart extends ShapeNodeEditPart {

	/**
	 * @generated
	 */
	public static final int VISUAL_ID = 1001;

	/**
	 * @generated
	 */
	protected IFigure contentPane;

	/**
	 * @generated
	 */
	protected IFigure primaryShape;

	/**
	 * @generated
	 */
	public PointcutEditPart(View view) {
		super(view);
	}

	/**
	 * @generated
	 */
	protected void createDefaultEditPolicies() {

		super.createDefaultEditPolicies();
		installEditPolicy(
				EditPolicyRoles.SEMANTIC_ROLE,
				new Clases.diagram.edit.policies.PointcutItemSemanticEditPolicy());
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
		// XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies
		// removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE);
	}

	/**
	 * @generated
	 */
	protected LayoutEditPolicy createLayoutEditPolicy() {
		LayoutEditPolicy lep = new LayoutEditPolicy() {

			protected EditPolicy createChildEditPolicy(EditPart child) {
				EditPolicy result = child
						.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
				if (result == null) {
					result = new NonResizableEditPolicy();
				}
				return result;
			}

			protected Command getMoveChildrenCommand(Request request) {
				return null;
			}

			protected Command getCreateCommand(CreateRequest request) {
				return null;
			}
		};
		return lep;
	}

	/**
	 * @generated
	 */
	protected IFigure createNodeShape() {
		PointcutFigure figure = new PointcutFigure();
		return primaryShape = figure;
	}

	/**
	 * @generated
	 */
	public PointcutFigure getPrimaryShape() {
		return (PointcutFigure) primaryShape;
	}

	/**
	 * @generated
	 */
	protected boolean addFixedChild(EditPart childEditPart) {
		if (childEditPart instanceof Clases.diagram.edit.parts.PointcutNombreEditPart) {
			((Clases.diagram.edit.parts.PointcutNombreEditPart) childEditPart)
					.setLabel(getPrimaryShape().getFigurePointcutNombreFigure());
			return true;
		}
		return false;
	}

	/**
	 * @generated
	 */
	protected boolean removeFixedChild(EditPart childEditPart) {

		return false;
	}

	/**
	 * @generated
	 */
	protected void addChildVisual(EditPart childEditPart, int index) {
		if (addFixedChild(childEditPart)) {
			return;
		}
		super.addChildVisual(childEditPart, -1);
	}

	/**
	 * @generated
	 */
	protected void removeChildVisual(EditPart childEditPart) {
		if (removeFixedChild(childEditPart)) {
			return;
		}
		super.removeChildVisual(childEditPart);
	}

	/**
	 * @generated
	 */
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {

		return super.getContentPaneFor(editPart);
	}

	/**
	 * @generated
	 */
	protected NodeFigure createNodePlate() {
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode()
				.DPtoLP(100), getMapMode().DPtoLP(20));
		return result;
	}

	/**
	 * Creates figure for this edit part.
	 * 
	 * Body of this method does not depend on settings in generation model
	 * so you may safely remove <i>generated</i> tag and modify it.
	 * 
	 * @generated
	 */
	protected NodeFigure createNodeFigure() {
		NodeFigure figure = createNodePlate();
		figure.setLayoutManager(new StackLayout());
		IFigure shape = createNodeShape();
		figure.add(shape);
		contentPane = setupContentPane(shape);
		return figure;
	}

	/**
	 * Default implementation treats passed figure as content pane.
	 * Respects layout one may have set for generated figure.
	 * @param nodeShape instance of generated figure class
	 * @generated
	 */
	protected IFigure setupContentPane(IFigure nodeShape) {
		if (nodeShape.getLayoutManager() == null) {
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
			layout.setSpacing(getMapMode().DPtoLP(5));
			nodeShape.setLayoutManager(layout);
		}
		return nodeShape; // use nodeShape itself as contentPane
	}

	/**
	 * @generated
	 */
	public IFigure getContentPane() {
		if (contentPane != null) {
			return contentPane;
		}
		return super.getContentPane();
	}

	/**
	 * @generated
	 */
	public EditPart getPrimaryChildEditPart() {
		return getChildBySemanticHint(Clases.diagram.part.ClasesVisualIDRegistry
				.getType(Clases.diagram.edit.parts.PointcutNombreEditPart.VISUAL_ID));
	}

	/**
	 * @generated
	 */
	public class PointcutFigure extends RectangleFigure {

		/**
		 * @generated
		 */
		private WrapLabel fFigurePointcutNombreFigure;

		/**
		 * @generated
		 */
		public PointcutFigure() {

			GridLayout layoutThis = new GridLayout();
			layoutThis.numColumns = 2;
			layoutThis.makeColumnsEqualWidth = false;
			this.setLayoutManager(layoutThis);

			this.setBackgroundColor(THIS_BACK);
			this.setPreferredSize(new Dimension(getMapMode().DPtoLP(100),
					getMapMode().DPtoLP(20)));
			createContents();
		}

		/**
		 * @generated
		 */
		private void createContents() {

			WrapLabel pointcutNombreFigure0 = new WrapLabel();
			pointcutNombreFigure0.setText("Nombre Pointcut :");
			pointcutNombreFigure0
					.setForegroundColor(POINTCUTNOMBREFIGURE0_FORE);

			pointcutNombreFigure0.setFont(POINTCUTNOMBREFIGURE0_FONT);

			GridData constraintPointcutNombreFigure0 = new GridData();
			constraintPointcutNombreFigure0.verticalAlignment = GridData.CENTER;
			constraintPointcutNombreFigure0.horizontalAlignment = GridData.CENTER;
			constraintPointcutNombreFigure0.horizontalIndent = 0;
			constraintPointcutNombreFigure0.horizontalSpan = 1;
			constraintPointcutNombreFigure0.verticalSpan = 1;
			constraintPointcutNombreFigure0.grabExcessHorizontalSpace = true;
			constraintPointcutNombreFigure0.grabExcessVerticalSpace = true;
			this.add(pointcutNombreFigure0, constraintPointcutNombreFigure0);

			fFigurePointcutNombreFigure = new WrapLabel();
			fFigurePointcutNombreFigure.setText("<...>");

			fFigurePointcutNombreFigure
					.setFont(FFIGUREPOINTCUTNOMBREFIGURE_FONT);

			GridData constraintFFigurePointcutNombreFigure = new GridData();
			constraintFFigurePointcutNombreFigure.verticalAlignment = GridData.CENTER;
			constraintFFigurePointcutNombreFigure.horizontalAlignment = GridData.CENTER;
			constraintFFigurePointcutNombreFigure.horizontalIndent = 0;
			constraintFFigurePointcutNombreFigure.horizontalSpan = 1;
			constraintFFigurePointcutNombreFigure.verticalSpan = 1;
			constraintFFigurePointcutNombreFigure.grabExcessHorizontalSpace = true;
			constraintFFigurePointcutNombreFigure.grabExcessVerticalSpace = true;
			this.add(fFigurePointcutNombreFigure,
					constraintFFigurePointcutNombreFigure);

		}

		/**
		 * @generated
		 */
		private boolean myUseLocalCoordinates = false;

		/**
		 * @generated
		 */
		protected boolean useLocalCoordinates() {
			return myUseLocalCoordinates;
		}

		/**
		 * @generated
		 */
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
			myUseLocalCoordinates = useLocalCoordinates;
		}

		/**
		 * @generated
		 */
		public WrapLabel getFigurePointcutNombreFigure() {
			return fFigurePointcutNombreFigure;
		}

	}

	/**
	 * @generated
	 */
	static final Color THIS_BACK = new Color(null, 175, 175, 255);

	/**
	 * @generated
	 */
	static final Color POINTCUTNOMBREFIGURE0_FORE = new Color(null, 0, 0, 0);

	/**
	 * @generated
	 */
	static final Font POINTCUTNOMBREFIGURE0_FONT = new Font(Display
			.getCurrent(),
			Display.getDefault().getSystemFont().getFontData()[0].getName(), 9,
			SWT.BOLD);

	/**
	 * @generated
	 */
	static final Font FFIGUREPOINTCUTNOMBREFIGURE_FONT = new Font(Display
			.getCurrent(),
			Display.getDefault().getSystemFont().getFontData()[0].getName(), 9,
			SWT.ITALIC);

}
